package domain;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;

/**
 * @author ganbo
 * @date 2022/12/7 21:33
 */


@AllArgsConstructor
@Data
public class User extends Person implements Comparable<User>, Comparator<User> {

    private Long id;
    private String name;

    @Override
    public int compareTo(User o) {
        return Long.compare(id, o.id);
    }


    public static void main(String[] args) {

        User u1 = new User(1L, "aaa");
        User u2 = new User(3L, "bbb");
        User u3 = new User(2L, "ccc");

        List<User> list = new ArrayList<>();
        list.add(u1);
        list.add(u2);
        list.add(u3);


//        System.out.println(list);
//        Collections.sort(list);
//        System.out.println(list);


        System.out.println(list);
        list.sort(new User(100L, "100ccc"));

        list.sort((Comparator.comparingLong(o -> o.id)));
        System.out.println(list);
    }

    @Override
    public int compare(User o1, User o2) {
        return Long.compare(o1.id, o2.id);
    }
}
